package me.ree.zkproduct.common.impl;

import me.ree.zkproduct.common.ConnectionPool;

import java.sql.Connection;
import java.util.ArrayList;
import java.util.List;

public class SimpleConnectionPool implements ConnectionPool {

    private List<Connection> connectionList = new ArrayList<>();

    @Override
    public void addConnection(Connection connection) {
        connectionList.add(connection);
    }

    @Override
    public Connection getConnection() {
        return connectionList.isEmpty() ? null : connectionList.get(0);
    }

    public int getConnectionNum() {
        return connectionList.size();
    }

    @Override
    public void close() {
        connectionList.clear();
    }
}
